import json

from fastapi import Request, APIRouter, Body
from datetime import datetime, timedelta
from core.Auth import decode_access_token
from core.Response import success, fail
from core.Utils import process_payment_request, random_str
from models.models import SiteInfo
from schemas.posts import SiteInfo_Pydantic

router = APIRouter(prefix='')

@router.get('/')
async def acement(request: Request):
    # cached_posts = await request.app.state.cache.get('acement')
    # if cached_posts:
    #     print("从缓存中获取数据")
    #     return success(data=json.loads(cached_posts))

    acement=await SiteInfo.get_or_none(id=1)
    # 序列化数据
    if not acement:
        return fail(msg="数据不存在")
    site_info_data = SiteInfo_Pydantic.from_orm(acement)
    print("从数据库中获取数据", site_info_data)
    await request.app.state.cache.set('acement', json.dumps(site_info_data, default=str))
    return success(data=site_info_data)